package top.idcard.agent.biz.rw.read.device;

import top.idcard.agent.biz.entity.AlienResidentCertificate;
import top.idcard.agent.biz.entity.Certification;
import top.idcard.agent.biz.entity.NativeIDCard;
import top.idcard.agent.biz.entity.WorkResidentCertificate;
import top.idcard.agent.biz.rw.read.AbstractRead;

public class CVRDeviceRead extends AbstractRead<CVRNativeFunction, Certification> {

    public CVRDeviceRead(CVRNativeFunction input) {
        super(input);
    }

    @Override
    public Certification nextObject() {
        Certification certification = null;
        switch (this.input.getCertType()){
            case Native:
                certification = readNative();
                break;
            case Hong:
                certification = readHong();
                break;
            case Foreign:
                certification = readForeign();
                break;
            default:
                certification = readNative();
        }
        return certification;
    }

    @Override
    public String readToType() {
        return "device_local";
    }

    private Certification readNative() {
        NativeIDCard nativeIDCard = new NativeIDCard();
        nativeIDCard.setNo(this.input.getPeopleIDCode());
        nativeIDCard.setName(this.input.getPeopleName());
        nativeIDCard.setSex(this.input.getPeopleSex());
        nativeIDCard.setBirthday(this.input.getPeopleBirthday());
        nativeIDCard.setNation(this.input.getPeopleNation());
        nativeIDCard.setAddr(this.input.getPeopleAddress());
        nativeIDCard.setSignOrganization(this.input.getDepartment());
        nativeIDCard.setValidationStart(this.input.getStartDate());
        nativeIDCard.setValidationEnd(this.input.getEndDate());
        nativeIDCard.setFingerprint(this.input.getFPDate().getBytes());
        nativeIDCard.setImg(this.input.getBMPData().getBytes());
        return nativeIDCard;
    }

    private Certification readHong() {
        WorkResidentCertificate card = new WorkResidentCertificate();
        return card;
    }

    private Certification readForeign() {
        AlienResidentCertificate card = new AlienResidentCertificate();
        return card;
    }

}
